package me.jiatao.recyclerviewstudy;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.StaggeredGridLayoutManager;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {

    private RecyclerView recyclerView;
    private List<String> stringList;
    private RecyclerAdapter adapter;

    @Override

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        recyclerView = findViewById(R.id.recycler_view);
        stringList = new ArrayList<>();
        adapter = new RecyclerAdapter(this, stringList);

        initRecyclerView();
        initData();
    }


    private void initRecyclerView() {
//        GridLayoutManager layoutManager = new GridLayoutManager(this,3);
//        layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
//        layoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
//            @Override
//            public int getSpanSize(int position) {
//                if (position == 3) {
//                    return 2;
//                }
//                if (position == 7) {
//                    return 3;
//                }
//                return 1;
//
//            }
//        });


        StaggeredGridLayoutManager layoutManager = new StaggeredGridLayoutManager(3, StaggeredGridLayoutManager.VERTICAL);
        recyclerView.setLayoutManager(layoutManager);
        recyclerView.setAdapter(adapter);
    }

    private void initData() {
        for (int i = 0; i < 100; i++) {
            stringList.add("item-->" + i);
        }

        adapter.notifyDataSetChanged();
    }

}
